package com.zerosky.crm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.zerosky.crm.dao.InviteDAO;
import com.zerosky.crm.po.Invite;
import com.zerosky.crm.service.InviteService;
import com.zerosky.crm.util.PageInfo;

/**
 * Invite业务逻辑实现类
 * 
 * @author 周正祥;
 * @since 2017-07-13
 *
 */
@Service(value="inviteService")
public class InviteServiceImpl implements InviteService {

	@Autowired
	private InviteDAO InviteDAO; // Invite数据接口

	/**
	 * Invite列表
	 * 
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public PageInfo<Invite> getInviteList(Map map) {
		PageInfo<Invite> page = new PageInfo<Invite>();
		if (map.get("page") != null && map.get("pageSize") != null) {
			int begin = (((int) map.get("page") - 1) * (int) map.get("pageSize"));

			// 写入数据
			map.put("pageNo", begin);
		}
		List<Invite> list = InviteDAO.getInviteList(map);
		page.setList(list);

		int count = InviteDAO.getInviteListCount(map);// 获取总记录
		page.setPageCount(count);
		return page;
	}

	/**
	 * 通过主键查找Invite实体
	 * 
	 * @param id
	 *            Invite主键
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.NOT_SUPPORTED) // 不开启事务
	public Invite getInviteById(String id) {
		return InviteDAO.getInviteById(id);
	}

	/**
	 * 保存Invite
	 * 
	 * @param Invite
	 *            实体对象, operation 操作类型
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void saveInvite(Invite Invite, String operation) {
		if ("新增".equalsIgnoreCase(operation)) {
			InviteDAO.addInvite(Invite);
		} else if ("修改".equalsIgnoreCase(operation)) {
			InviteDAO.updateInvite(Invite);
		}

	}

	/**
	 * 删除Invite
	 * 
	 * @param idArray
	 *            Invite主键数组
	 * @author 钟璟;
	 * @since 2017-07-13
	 */
	@Transactional(propagation = Propagation.REQUIRED) // 创建一个事务，如果有则加入事务
	public void deleteInviteById(Map<String,Object> map) {
		InviteDAO.deleteInviteById(map);

	}

	/**
	 * 获取邀约统计量
	 */
	public Invite getStatisticalMagnitude(Integer activityId) {
		return InviteDAO.getStatisticalMagnitude(activityId);
	}

}
